import { fetchList } from './api'

export default {
  namespaced: true,
  state: () => ({
    list: [],
    total: 0
  }),
  getters: {
    list (state) {
      return state.list
    },
    total (state) {
      return state.total
    }
  },
  actions: {
    async fetchList ({ commit }, params) {
      const payload = await fetchList(params)
      commit('SET_LIST', payload)
      return Promise.resolve()
    }
  },
  mutations: {
    SET_LIST (state, payload) {
      state.list = payload.data
      state.total = payload.extra.total
    }
  }
}
